home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11479 < prev    next >
Encoding:
Text File  |  1996-08-05  |  964 b   |  41 lines

  1. Path: solon.com!not-for-mail
  2. From: yang@math.umass.edu (Huayong Yang)
  3. Newsgroups: comp.lang.c,comp.lang.c.moderated
  4. Subject: Re: const pointer confusion...
  5. Date: 24 Mar 1996 11:42:48 -0600
  6. Organization: UMass/Amherst Dept Math & Stats
  7. Sender: clc@solutions.solon.com
  8. Approved: clc@solutions.solon.com
  9. Message-ID: <4j41io$nma@solutions.solon.com>
  10. References: <4j06gm$7oa@solutions.solon.com>
  11. NNTP-Posting-Host: solutions.solon.com
  12. X-Newsreader: Tin 1.1 PL362948
  13.  
  14.  
  15. const int *p and int const *p are the same: a pointer to const integer;
  16. int * const p means a const pointer to integer. A little program to
  17. verify it:
  18.  
  19. int main()
  20. {
  21.   int a = 10;
  22.   const int *b = &a;
  23.   int const *c = &a;
  24.   int * const d = &a;
  25.   int e = 15;
  26.   b = &e;
  27.   /* WRONG: *b = 20; */
  28.   c = &e;
  29.   /* WRONG: *c = 20; */
  30.   /* WRONG: d = &e; */
  31.   *d = 20;
  32.   return 0;
  33. }
  34.  
  35.    
  36. --
  37. Huayong
  38.  
  39. WWW home pages:                           Email:
  40. http://www.math.umass.edu/~yang           yang@math.umass.edu
  41.